//package com.pug.security.config;
//
//import com.pug.security.file.VerificationFilter;
//import com.pug.security.handler.MyAuthenticationProvider;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.crypto.password.PasswordEncoder;
//import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
//
//import javax.sql.DataSource;
//
///**
// * @program: xq_pug_alibabacloud_parent
// * @description:
// * @author: Mr.Ren
// * @create: 2023-07-16 22:09
// **/
//@Configuration
//@EnableWebSecurity
//public class SecurityConfig03 extends WebSecurityConfigurerAdapter {
//
//    @Autowired
//    private DataSource dataSource;
//    @Autowired
//    private UserDetailsService userDetailsService;
//    @Autowired
//    private VerificationFilter verificationFilter;
//    /**
//     * 自定义认证类
//     */
//    @Autowired
//    private MyAuthenticationProvider myAuthenticationProvider;
//
//
//    //认证
//    @Override
//    protected void configure(HttpSecurity http) throws Exception {
//        http.authorizeRequests()
//                //放行api开头的请求
//                .antMatchers("/api/**").permitAll()
//                //所有请求都需要认证才能访问
//                .anyRequest().authenticated()
//                .and()
//                //开启表单认证方式
//                .formLogin()
//                .and()
//                //关闭古老的basic认证方式
//                .httpBasic().disable();
//
//        //配置执行器的顺序
//        http.addFilterBefore(verificationFilter, UsernamePasswordAuthenticationFilter.class);
//    }
//
//
//    //授权
//    @Override
//    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//        //此处配置是基于内存还是基于数据库
//
//        //方式1：基于内存
//
//        //方式2：基于官方推荐H2数据库
//        //auth.jdbcAuthentication().dataSource(dataSource);
//
//        //方式3：基于userDetailsService
////        auth.userDetailsService(userDetailsService)
////                //密码加密
////                .passwordEncoder(passwordEncoder());
//
//        //方式4：基于userDetailsService+自定义认证类
//        auth.authenticationProvider(myAuthenticationProvider)
//                .userDetailsService(userDetailsService);
//    }
//
//    /**
//     * 密码加密工具
//     *
//     * @return
//     */
//    @Bean
//    public PasswordEncoder passwordEncoder() {
//        return new BCryptPasswordEncoder();
//    }
//}
